package leetcode.editor.cn;

//给你一个字符串 s ，其中包含字母顺序打乱的用英文单词表示的若干数字（0-9）。按 升序 返回原始的数字。 
//
// 
//
// 示例 1： 
//
// 
//输入：s = "owoztneoer"
//输出："012"
// 
//
// 示例 2： 
//
// 
//输入：s = "fviefuro"
//输出："45"
// 
//
// 
//
// 提示： 
//
// 
// 1 <= s.length <= 10⁵ 
// s[i] 为 ["e","g","f","i","h","o","n","s","r","u","t","w","v","x","z"] 这些字符之一 
// s 保证是一个符合题目要求的字符串 
// 
// Related Topics 哈希表 数学 字符串 👍 169 👎 0

import java.util.HashMap;
import java.util.Map;

//Java：从英文中重建数字
public class ReconstructOriginalDigitsFromEnglish_423{
    public static void main(String[] args) {
        Solution solution = new ReconstructOriginalDigitsFromEnglish_423().new Solution();
        // TO TEST
        // "e","g","f","i","h","o","n","s","r","u","t","w","v","x","z"
    }
    
    //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public String originalDigits(String s) {
        int length=s.length();
        Map<Character,Integer> map = new HashMap<>();
        for (int i = 0; i < length; i++) {
            char c = s.charAt(i);
            int count = map.getOrDefault(c, 0)+1;
            map.put(c,count);
        }
        int[] num = new int[10];
        num[0] = map.getOrDefault('z',0);
        num[2] = map.getOrDefault('w',0);
        num[4] = map.getOrDefault('u',0);
        num[6] = map.getOrDefault('x',0);
        num[8] = map.getOrDefault('g',0);
        num[1] = map.getOrDefault('o',0)-num[0]-num[2]-num[4];
        num[3] = map.getOrDefault('h',0)-num[8];
        num[5] = map.getOrDefault('f',0)-num[4];
        num[7] = map.getOrDefault('s',0)-num[6];
        num[9] = map.getOrDefault('i',0)-num[5]-num[6]-num[8];
        StringBuffer res = new StringBuffer();
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < num[i]; j++) {
                res.append((char)(i+'0'));
            }
        }
        return res.toString();
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}
